package com.kujie.langchain4j.controller;

import com.kujie.langchain4j.chat.assistant.CkAssistant;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.service.AiServices;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * AI服务
 *
 * @author check
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class AiController {
    private final OpenAiStreamingChatModel chatModel;

    @GetMapping("/call")
    public Flux<String> call(@RequestParam("input") String input) {
        CkAssistant ckAssistant = AiServices.create(CkAssistant.class, chatModel);
        return ckAssistant.chatWithStream(input);
    }
}
